package com.lb.activity.mapper;

import com.lb.activity.po.User;
import com.lb.activity.po.UserExample;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserMapper {
    int countByExample(UserExample example);

    int deleteByExample(UserExample example);

    int deleteByPrimaryKey(Long id);

    int insert(User record);

    int insertSelective(User record);

    List<User> selectByExample(UserExample example);

    User selectByPrimaryKey(Long id);

    int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example);

    int updateByExample(@Param("record") User record, @Param("example") UserExample example);

    int updateByPrimaryKeySelective(User record);

    int updateByPrimaryKey(User record);

    @Select(" SELECT  id, user_name, password,\n" +
            "      group_id, status, create_time,\n" +
            "      update_time FROM USER WHERE user_name = #{username} AND STATUS = 0")
    @ResultMap("com.lb.activity.mapper.UserMapper.BaseResultMap")
    User selectByUserLoginName(String username);

    /**
     * 查询所有用户
     * @return
     */
    @Select("<script>select id, user_name, group_id, status, create_time,update_time from user  " +
            " <if test= \"groupId != null\"> where group_id = #{groupId,jdbcType=BIGINT} </if> </script>")
    @ResultMap("com.lb.activity.mapper.UserMapper.BaseResultMap")
    List<User> selectUserList(@Param("groupId")Long groupId);
}